package mortal.game.control
{
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import flash.events.*;
    import flash.net.*;
    import modules.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.model.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class QuickRegisterController extends Controller
    {
        private var _quickRegisterBtn:GButton;
        private var _quickRegisterPanel:QuickRegisterModule;

        public function QuickRegisterController()
        {
            Dispatcher.addEventListener(EventName.QuickRegister, this.onQuickRegister);
            
        }

        public function init() : void
        {
            if (ParamsConst.instance.guest == 0)
            {
                if (!this._quickRegisterBtn)
                {
                    this._quickRegisterBtn = ObjCreate.createGButton("快速注册4399账号", 0, 0, 130, 27, GameController.gameui.getGameui(), "Button3");
                    this._quickRegisterBtn.addEventListener(MouseEvent.CLICK, this.onQuickRegisterBtnClick);
                }
                this.initView();
            }
            
        }

        override protected function initView() : IView
        {
            if (!this._quickRegisterPanel)
            {
                this._quickRegisterPanel = new QuickRegisterModule();
            }
            return this._quickRegisterPanel;
        }

        private function onQuickRegisterBtnClick(event:MouseEvent) : void
        {
            if (this._quickRegisterPanel.isHide)
            {
                this._quickRegisterPanel.show();
                PopupManager.centerPopup(this._quickRegisterPanel);
            }
            else
            {
                this._quickRegisterPanel.hide();
            }
            
        }

        private function onQuickRegister(event:DataEvent) : void
        {
            var _loc_2:* = event.data as QuickRegisterInfo;
            if (_loc_2.passWord != _loc_2.rePassWord)
            {
                MsgManager.addBroadCast("密码输入不一致！");
                
            }
            var _loc_3:* = new URLRequest(ParamsConst.instance.quickRegisterUrl);
            _loc_3.method = URLRequestMethod.GET;
            var _loc_4:* = new URLVariables();
            new URLVariables().username = encodeURI(_loc_2.userName);
            _loc_4.password = _loc_2.passWord;
            _loc_4.email = _loc_2.email;
            _loc_3.data = _loc_4;
            var _loc_5:* = new URLLoader();
            new URLLoader().addEventListener(Event.COMPLETE, this.onComplete);
            _loc_5.load(_loc_3);
            
        }

        private function onComplete(event:Event) : void
        {
            var _loc_2:* = event.target as URLLoader;
            switch(_loc_2.data)
            {
                case "1":
                {
                    BrowerUtil.reload();
                    break;
                }
                case "-1":
                {
                    MsgManager.addBroadCast("参数不全！");
                    break;
                }
                case "-2":
                {
                    MsgManager.addBroadCast("用户名不合法！");
                    break;
                }
                case "-3":
                {
                    MsgManager.addBroadCast("Email地址不合法！");
                    break;
                }
                case "-4":
                {
                    MsgManager.addBroadCast("超时，链接失效！");
                    break;
                }
                case "-5":
                {
                    MsgManager.addBroadCast("验证失败！");
                    break;
                }
                case "-6":
                {
                    MsgManager.addBroadCast("平台暂停注册！");
                    break;
                }
                case "-7":
                {
                    MsgManager.addBroadCast("未知原因，用户注册失败！");
                    break;
                }
                case "-21":
                {
                    MsgManager.addBroadCast("用户名已经存在！");
                    break;
                }
                case "-22":
                {
                    MsgManager.addBroadCast("邮箱已经存在！");
                    break;
                }
                default:
                {
                    MsgManager.addBroadCast("快速注册失败！");
                    break;
                    break;
                }
            }
            
        }

        public function stageResize() : void
        {
            if (this._quickRegisterBtn)
            {
                this._quickRegisterBtn.x = Global.stage.stageWidth - 268;
                this._quickRegisterBtn.y = 140;
            }
            
        }

    }
}
